package com.en.sharing.serviceprovider.bpm;

/**
 * 任务抽象
 *
 * @author 付晓飞
 * @date 2024/3/11 7:00 下午
 */
public final class OperateApprovalTaskBo<T> {

    /**
     * 操作类型
     */
    private final OperateTypeEnum operateType;

    /**
     * 操作条目
     */
    private final IOperationEntryCode operationEntryCode;

    /**
     * 老数据
     */
    private final T oldData;

    /**
     * 新数据
     */
    private final T newData;

    private OperateApprovalTaskBo(OperateTypeEnum operateType, IOperationEntryCode operationEntryCode, T oldData, T newData) {
        this.operateType = operateType;
        this.operationEntryCode = operationEntryCode;
        this.oldData = oldData;
        this.newData = newData;
    }

    public static <T> OperateApprovalTaskBo<T> newTaskForUpdate(IOperationEntryCode operationEntryCode, T oldData, T newData) {
        if (oldData == null || newData == null) {
            throw new IllegalArgumentException("oldData or newData is null");
        }
        if (operationEntryCode == null) {
            throw new IllegalArgumentException("operationEntryCode is null");
        }
        return new OperateApprovalTaskBo<>(OperateTypeEnum.UPDATE, operationEntryCode, oldData, newData);
    }

    public static <T> OperateApprovalTaskBo<T> newTaskForDelete(IOperationEntryCode operationEntryCode, T oldData) {
        if (oldData == null) {
            throw new IllegalArgumentException("oldData is null");
        }
        if (operationEntryCode == null) {
            throw new IllegalArgumentException("operationEntryCode is null");
        }
        return new OperateApprovalTaskBo<>(OperateTypeEnum.DELETE, operationEntryCode, oldData, null);
    }

    public static <T> OperateApprovalTaskBo<T> newTaskForInsert(IOperationEntryCode operationEntryCode, T newData) {
        if (newData == null) {
            throw new IllegalArgumentException("newData is null");
        }
        if (operationEntryCode == null) {
            throw new IllegalArgumentException("operationEntryCode is null");
        }
        return new OperateApprovalTaskBo<>(OperateTypeEnum.INSERT, operationEntryCode, null, newData);
    }

    public OperateTypeEnum getOperateType() {
        return operateType;
    }

    public IOperationEntryCode getOperationEntryCode() {
        return operationEntryCode;
    }

    public T getOldData() {
        return oldData;
    }

    public T getNewData() {
        return newData;
    }
}
